/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package postgresql;
import java.sql.DriverManager;
import java.sql.Connection;
import java.sql.SQLException;
import java.sql.*;

/**
 *
 * @author hp g42
 */
public class PostgreSQL {

    /**
     * @param args the command line arguments
     */
    public static void main(String[] args) {
        // TODO code application logic here
        try{
            Class.forName("org.postgresql.Driver");
            
        }
        catch(ClassNotFoundException cnfe){
            cnfe.printStackTrace();
            System.exit(1);
        }
        
        Connection c = null;
        
        try{
            c = DriverManager.getConnection("jdbc:postgresql://localhost/pbb","postgres","postgresql");            
        }
        catch(SQLException se){
            se.printStackTrace();
            System.exit(1);
        }
        
        if(c!=null){
            System.out.println("connected");
        }
        
        Statement s = null;
        
        try{
            s = c.createStatement();
        }
        catch(SQLException se){
            se.printStackTrace();;
            System.exit(1);
        }
        
        ResultSet rs = null;
        try{
            rs = s.executeQuery("select * from pbb.pbb_sppt");
        }
        catch(SQLException se){
            se.printStackTrace();;
            System.exit(1);
        }
        
        int index = 0;
        try{
            while(rs.next()){
                System.out.print("Row: "+ index++ +" ");
                System.out.print(rs.getArray(1/*nomor kolom, mulai dari 1*/)+" ");
                System.out.print(rs.getArray(2)+" ");
                System.out.println(rs.getArray(3)+" ");
            }
        }
        catch(SQLException se){
            se.printStackTrace();;
            System.exit(1);
        }                    
    }
}
